export const handleChartData = (headerData, data) => {
  let legendData = []
  let xAxisData = []
  let seriesData = []
  for (let i = 0; i < headerData.length; i++) {
    // 初始化柱图数据
    if (headerData[i].name !== 'time' && headerData[i].name !== 'percent') {
      legendData.push(headerData[i].label)
      let obj = {
        name: headerData[i].label,
        type: 'line',
        data: []
      }
      for (let j = 0; j < data.length; j++) {
        let name = headerData[i].name
        obj.data.push(data[j][name])
      }
      seriesData.push(obj)
    }
  }
  for (let i = 0; i < data.length; i++) {
    xAxisData.push(data[i].time)
  }
  return {legendData, xAxisData, seriesData}
}

export const handleChartDataCompare = (headerData, data) => {
  let legendData = []
  let xAxisData = []
  let seriesData = []
  // 新用户/老用户
  for (let i = 0; i < data.length; i++) {
    // 初始化柱图数据
    legendData.push(data[i].time)
    let obj = {
      name: data[i].time,
      type: 'bar',
      data: []
    }
    obj.data.push(data[i]['userCountOne'])
    obj.data.push(data[i]['userPayCountOne'])
    seriesData.push(obj)
  }
  for (let i = 0; i < headerData.length; i++) {
    if (headerData[i].name !== 'time') {
      xAxisData.push(headerData[i].label.trim())
    }
  }
  return {legendData, xAxisData, seriesData}
}
